﻿using System;
using PSE.Deployment.Engine;
using PSE.Deployment.Engine.CustomEventArgs;
using PSE.Deployment.Engine.Enums;
using PSE.Deployment.Engine.Interfaces;

namespace PSE.Deployment.SetupBase.Steps
{
    public class InstallationMode : BaseStep
    {
        private UI.InstallationMode installationMode;
        public StepNavigationAction NavigationAction { get; protected set; }

        public InstallationMode(IStepGroup parent)
            : base(parent)
        {
            this.Id = "SetupModeStep";
            this.Description = "SetupModeStep";
            this.ErrorBehavior = StepErrorBehavior.CancelParent;
            this.NavigationBehavior = StepNavigationBehavior.NextCancel;

            this.ExecutionFinished += new EventHandler<ExecutionFinishedEventArgs>(InstallationMode_ExecutionFinished);
        }

        void InstallationMode_ExecutionFinished(object sender, ExecutionFinishedEventArgs e)
        {
            e.NavigationAction = this.NavigationAction;
        }

        public override void Execute()
        {
            installationMode = new UI.InstallationMode();
            installationMode.ShowDialog();
            SetupMainFactory.GetInstance().Parameter.SetupMode = installationMode.SelectedSetupMode;
            this.NavigationAction = installationMode.NavigationAction.GetValueOrDefault();
        }

        public override void Undo()
        {
            if (installationMode != null)
                installationMode.Close(false);
        }
    }
}
